package com.xjy.system.service.impl;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.StrUtil;
import com.xjy.common.utils.PageUtils;
import com.xjy.common.core.page.PagePlus;
import com.xjy.common.core.page.TableDataInfo;
import org.springframework.stereotype.Service;
import com.xjy.common.core.mybatisplus.core.ServicePlusImpl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.xjy.system.domain.bo.ReportBudgetIncomeQueryBo;
import com.xjy.system.domain.ReportBudgetIncome;
import com.xjy.system.mapper.ReportBudgetIncomeMapper;
import com.xjy.system.domain.vo.ReportBudgetIncomeVo;
import com.xjy.system.service.IReportBudgetIncomeService;

import java.util.List;
import java.util.Map;
import java.util.Collection;

/**
 * 预算支出执行报告Service业务层处理
 *
 * @author mlb
 * @date 2022-03-08
 */
@Service
public class ReportBudgetIncomeServiceImpl extends ServicePlusImpl<ReportBudgetIncomeMapper, ReportBudgetIncome> implements IReportBudgetIncomeService {

    @Override
    public ReportBudgetIncomeVo queryById(Long subjectId){
        return getVoById(subjectId, ReportBudgetIncomeVo.class);
    }

    @Override
    public TableDataInfo<ReportBudgetIncomeVo> queryPageList(ReportBudgetIncomeQueryBo bo) {
        PagePlus<ReportBudgetIncome, ReportBudgetIncomeVo> result = pageVo(PageUtils.buildPagePlus(), buildQueryWrapper(bo), ReportBudgetIncomeVo.class);
        return PageUtils.buildDataInfo(result);
    }

    @Override
    public List<ReportBudgetIncomeVo> queryList(ReportBudgetIncomeQueryBo bo) {
        return listVo(buildQueryWrapper(bo), ReportBudgetIncomeVo.class);
    }

    private LambdaQueryWrapper<ReportBudgetIncome> buildQueryWrapper(ReportBudgetIncomeQueryBo bo) {
        Map<String, Object> params = bo.getParams();
        LambdaQueryWrapper<ReportBudgetIncome> lqw = Wrappers.lambdaQuery();
        lqw.eq(bo.getSubjectId() != null, ReportBudgetIncome::getSubjectId, bo.getSubjectId());
        lqw.like(StrUtil.isNotBlank(bo.getSubjectName()), ReportBudgetIncome::getSubjectName, bo.getSubjectName());
        lqw.eq(bo.getProjId() != null, ReportBudgetIncome::getProjId, bo.getProjId());
        return lqw;
    }

}
